/**
* @file qoudp.cpp
* @describe UDP通信
* @author gaoyuelong
* @date 2021/11/23
*/

#include <QNetworkDatagram>
#include <QDebug>
#include "qoudp.h"

QoUdp::QoUdp() :
    m_pUdpSocket(nullptr),
    m_hostAddress("127.0.0.1"),
    m_iPort(8888)
{
    m_pUdpSocket = new QUdpSocket();
    m_pUdpSocket->bind(m_hostAddress, m_iPort);

    connect(m_pUdpSocket, SIGNAL(readRead()), this, SLOT(readData()));
}

QoUdp::~QoUdp()
{

}

void QoUdp::readData()
{
    while (m_pUdpSocket->hasPendingDatagrams()) {
        QNetworkDatagram datagram = m_pUdpSocket->receiveDatagram();
        qDebug() << QString(datagram.data());
    }
}

